#include <iostream>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

int infix(string);

int main()
{
	string exp = "2 - 4 + 2";
	cout << exp << " = " << infix(exp) << endl;

	system("pause");
	return 0;
}

int infix(string exp)
{
	stack<string> operators;
	stack<int> operands;

	string in = "";
	string previousIn = "";
	istringstream iss(exp);

	int result = 0;

	while (getline(iss, in, ' '))
	{
		if (in == "+")
		{
			operators.push(in);
		}
		else if (in == "-")
		{
			operators.push(in);
		}
		else
		{
			operands.push(stoi(in));
		}
	}

	while (operators.size() != 0)
	{
		int operand = operands.top();
		operands.pop();
		if (operators.top() == "+")
		{
			result += operands.top() + operand;
			operands.pop();
			operators.pop();
		}
		else if (operators.top() == "-")
		{
			result += operands.top() - operand;
			operands.pop();
			operators.pop();
		}
		operands.push(result);
	}
	return result;
}

int calculate()